﻿function showDSCode(rid) {
	if (refreshWin('showDSCode' + rid)) return;
	getDSCode({
				rid : rid,
				success : onload
			});

	function onload(data) {
		var txtrid = new Ext.form.TextField({
					fieldLabel : 'RID',
					value : data.rid
				});
		var status = new Ext.form.TextField({
					fieldLabel : 'Status',
					style : 'font-weight:bold;color:' + sys.rd.getcolor(data.statusCode),
					value : data.status
							+ (!Ext.isEmpty(data.reInfo) ? ' (' + data.reInfo + ' ' + data.reCode
									+ ')' : '')
				});
		var author = new Ext.form.TextField({
					fieldLabel : 'Author',
					value : sys.rd.authorusername(data)
				});
		var exeTime = new Ext.form.TextField({
					fieldLabel : 'ExeTime',
					value : sys.rd.exetime(data.exeTime)
				});
		var pid = new Ext.form.TextField({
					fieldLabel : 'PID',
					value : 'e' + data.eid + '(' + int2char(data.pid) + ')'
				});
		var exeMem = new Ext.form.TextField({
					fieldLabel : 'ExeMemory',
					value : sys.rd.exemem(data.exeMem)
				});
		var lang = new Ext.form.TextField({
					fieldLabel : 'Language',
					value : data.lang
				});
		var submitTime = new Ext.form.TextField({
					fieldLabel : 'SubmitTime',
					value : data.submitTime
				});
		var code = new Ext.ux.HtmlViewer({
					fieldLabel : 'Code',
					anchor : '98% -108',
					value : data.code
				});

		var form = new Ext.FormPanel({
					frame : true,
					labelAlign : 'right',
					labelWidth : 60,
					items : [{
								layout : 'column',
								items : [{
											layout : 'form',
											columnWidth : .47,
											defaults : {
												anchor : '100%',
												readOnly : true
											},
											items : [txtrid, author, pid, lang]
										}, {
											layout : 'form',
											columnWidth : .53,
											labelWidth : 80,
											defaults : {
												anchor : '96.32%',
												readOnly : true
											},
											items : [status, exeTime, exeMem, submitTime]
										}]
							}, code]
				});

		var toolbar = new Ext.Toolbar();
		if (sys.god || sys.teacher) toolbar.add([new Ext.Button({
							text : '重判',
							iconCls : 'rejudge-icon',
							handler : onRejudge
						}), new Ext.Button({
							text : '测试',
							iconCls : 'test-icon',
							handler : onTest
						}), new Ext.Button({
							text : '删除',
							iconCls : 'delete-icon',
							handler : onDelete
						})]);
		toolbar.add([new Ext.Toolbar.Fill(), new Ext.Button({
							text : '关闭',
							iconCls : 'ok-icon',
							handler : function() {
								win.close();
							}
						})]);

		var win = new Ext.Window({
					id : 'showDSCode' + rid,
					title : '查看实验代码-' + rid,
					iconCls : 'code-icon',					width : 610,
					height : 410,
					minWidth : 300,
					minHeight : 300,
					layout : 'fit',
					items : form,
					bbar : toolbar
				});
		win.show();

		function onTest() {
			testDSStatus(data.rid);
			win.close();
		}
		function onRejudge() {
			rejudgeDSStatus({
						rid : data.rid,
						success : function() {
							win.close();
						}
					});
		}
		function onDelete() {
			deleteDSStatus({
						rid : data.rid,
						success : function() {
							win.close();
						}
					});
		}
	}
}

function getDSCode(obj) {
	ajax({
				url : url.getDSCode,
				params : {
					rid : obj.rid
				},
				success : obj.success
			});
}
